<template>
  <div class="bg_fafafa p-20 w_full h_full">
    <el-button size="small" class="mb-20" @click="handleBack">返回</el-button>
    <div class="bg_fff p-24">
      <div class="flexbetween">
        <div class="f-14">客服评价</div>
        <div class="flex">
          <div
            v-for="(item, index) in dayList"
            :key="index"
            class="dayitem mr-10 commhover f-14 flexcenter"
            :class="{ active: queryParams.day == item.num }"
            @click="handleDay(item)"
          >
            {{ item.name }}
          </div>
          <el-date-picker
            v-model="times"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="small"
          >
          </el-date-picker>
          <select-tree
            size="small"
            :treeList="treeList"
            nodeKey="id"
            :defaultData="defaultData"
            :treeProps="{
              children: 'children',
              label: 'label',
            }"
            @handleNodeClick="selectDrop"
            style="width: 200px"
            class="ml-10"
          />
          <el-select
            v-model="queryParams.status"
            size="small"
            placeholder="筛选状态"
            style="width: 150px"
            class="ml-10"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-button size="small" class="ml-10" @click="handleBack"
            >导出</el-button
          >
        </div>
      </div>
      <div class="flex flexwrap mt-15 mb-20">
        <div
          v-for="(item, index) in evalist"
          :key="index"
          class="numbox flex11"
        >
          <div class="box_num c_222333 f-25 fw-5">{{ item.num }}</div>
          <div class="box_title c_555666 f-14">{{ item.name }}</div>
        </div>
      </div>
      <div class="echarts-line" ref="echartsLine"></div>
      <!-- <LineChart height='300px' :chartData='chartData' /> -->
    </div>
    <div class="bg_fff p-24 mt-20">
      <el-table
        v-loading="loading"
        class="commtable chattable"
        :data="tableList"
      >
        <template v-for="(item, index) in tableColumnList">
          <el-table-column
            :key="index"
            :label="item.title"
            min-width="130px"
            :prop="item.prop"
            :fixed="item.fixed"
            v-if="item.show"
            :sortable="item.sortable"
          >
            <template slot-scope="scope">
              <div v-if="item.prop == 'status'">
                <svg-icon
                  v-if="scope.row.status == 1"
                  icon-class="sonline"
                  class-name="mr-5 f-14"
                />
                <svg-icon
                  v-if="scope.row.status == 2"
                  icon-class="leave"
                  class-name="mr-5 f-14"
                />
                <svg-icon
                  v-if="scope.row.status == 3"
                  icon-class="offline"
                  class-name="mr-5 f-14"
                />
                <span>上班</span>
              </div>
              <div v-else>
                {{ scope.row[item.prop] || "-" }}
              </div>
            </template>
          </el-table-column>
        </template>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>
<script>
import SelectTree from "@/components/SelectTree";
import * as echarts from 'echarts'
import LineChart from "@/views/dashboard/LineChart";
import resize from '@/views/dashboard/mixins/resize'
export default {
  mixins: [resize],
  data() {
    return {
      queryParams: {
        day: 1,
        pageNum: 1,
        pageSize: 10,
      },
      tableList: [{ ID: 1, name: "贝贝", status: 1, num: 0 }],
      total: 0,
      loading: false,
      dayList: [
        { name: "今天", num: 1 },
        { name: "昨天", num: 2 },
        { name: "7天", num: 7 },
        { name: "30天", num: 30 },
      ],
      times: "",
      treeList: [
        {
          id: 1,
          label: "一级 1",
          children: [
            {
              id: 2,
              label: "二级 1-1",
              children: [
                {
                  id: 3,
                  label: "三级 1-1-1",
                },
              ],
            },
          ],
        },
        {
          id: 4,
          label: "一级 2",
          children: [
            {
              id: 5,
              label: "二级 2-1",
              children: [
                {
                  id: 6,
                  label: "三级 2-1-1",
                },
              ],
            },
            {
              id: 7,
              label: "二级 2-2",
              children: [
                {
                  id: 8,
                  label: "三级 2-2-1",
                },
              ],
            },
          ],
        },
      ],
      defaultData: {
        value: "",
        name: "",
      },
      options: [
        { label: "上班", value: 1 },
        { label: "离开", value: 2 },
        { label: "下班", value: 3 },
      ],
      evalist: [
        { name: "总有效对话数", num: 0 },
        { name: "总参评率", num: 0 },
        { name: "好评总量", num: 0 },
        { name: "中评总量", num: 0 },
        { name: "差评总量", num: 0 },
      ],
      chart:null,
      chartData: {
        goodNums: [1, 2, 3, 5, 6, 234, 100],
        middleNums: [0, 4, 6, 5, 6, 224, 150],
        badNums: [0, 0, 0, 4, 2, 21, 10],
      },
      tableColumnList: [
        { title: "子账号ID", prop: "ID", fixed: true, show: true, sortable:false },
        { title: "客服姓名", prop: "name", fixed: true, show: true, sortable:false },
        { title: "当前状态", prop: "status", fixed: false, show: true, sortable:false },
        { title: "有效对话数", prop: "group", fixed: false, show: true, sortable:true },
        { title: "评价数", prop: "num", fixed: false, show: true, sortable:true },
        { title: "参评率", prop: "num", fixed: false, show: true, sortable:true },
        { title: "好评", prop: "num", fixed: false, show: true, sortable:true },
        { title: "中评", prop: "num", fixed: false, show: true, sortable:true },
        { title: "差评", prop: "num", fixed: false, show: true, sortable:true },
      ],
    };
  },
  components: {
    SelectTree,
    LineChart,
  },
  mounted() {
    this.initChart();
  },
  methods: {
    getList() {},

    initChart() {
      let data = new Array(24).fill(0);
      this.chart = echarts.init(this.$refs.echartsLine);
      this.chart.setOption({
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["好评", "中评", "差评"],
          bottom: '6',
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "15%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: [
            "0",
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "10",
            "11",
            "12",
            "13",
            "14",
            "15",
            "16",
            "17",
            "18",
            "19",
            "20",
            "21",
            "22",
            "23",
          ],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: "好评",
            type: "line",
            stack: "Total",
            itemStyle: {
              normal: {
                color: '#A5DB1E',
                lineStyle: {
                  color: '#A5DB1E',
                  width: 2
                }
              }
            },
            data: data,
          },
          {
            name: "中评",
            type: "line",
            stack: "Total",
            data: data,
            itemStyle: {
              normal: {
                color: '#4D84FF',
                lineStyle: {
                  color: '#4D84FF',
                  width: 2
                }
              }
            },
          },
          {
            name: "差评",
            type: "line",
            stack: "Total",
            data: data,
            itemStyle: {
              normal: {
                color: '#FA9223',
                lineStyle: {
                  color: '#FA9223',
                  width: 2
                }
              }
            },
          },
        ],
      });
    },

    handleBack() {
      this.$router.back();
    },

    handleDay(item) {
      this.queryParams.day = item.num;
    },

    selectDrop(val) {
      this.defaultData.value = val;
    },
  },
};
</script>

<style lang="scss" scoped>
.dayitem {
  height: 32px;
  line-height: 32px;
  width: 50px;
  background-color: #f4f6f8;
  &.active {
    background-color: #3070ff !important;
    color: #fff !important;
  }
}
.chattable {
  ::v-deep .el-table__header th {
    background-color: #f5f5f5;
    padding: 16px 0;
  }
}
.popheader {
  border-bottom: 1px solid #e9e9e9;
}
.popbox {
  .el-checkbox {
    width: 33%;
    margin-right: 0;
    margin-top: 5px;
  }
}
.numbox {
  height: 86px;
  background: #f5f5f5;
  margin-bottom: 12px;
  margin-right: 1.5%;
  padding: 16px 20px;
  vertical-align: middle;

  .box_num {
    line-height: 34px;
  }
}
.echarts-line {
  width: 100%;
  height: 360px;
}
</style>
